package com.example.demo.service.Impl;

import com.example.demo.entity.*;
import com.example.demo.mapper.FunctionPointMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.result.FunctionInfo;
import com.example.demo.service.FunctionPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class FunctionPointServiceImpl implements FunctionPointService {

    @Autowired
    FunctionPointMapper functionPointMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public FunctionInfo getFunctionInfo(FunctionPoint function) {
        FunctionInfo functioninfo = new FunctionInfo();

        functioninfo.setFunctionChargerId(function.getFunctionChargerId());
        functioninfo.setFunctionComplateScheduledTime(function.getFunctionComplateScheduledTime());
        functioninfo.setFunctionComplateTime(function.getFunctionComplateTime());
        functioninfo.setFunctionCurrentStage(function.getFunctionCurrentStage());
        functioninfo.setFunctionId(function.getFunctionId());
        functioninfo.setFunctionIteration(function.getFunctionIteration());
        functioninfo.setFunctionName(function.getFunctionName());
        functioninfo.setFunctionProId(function.getFunctionProId());
        functioninfo.setFunctionScheduledCostTime(function.getFunctionScheduledCostTime());
        functioninfo.setFunctionStartScheduledTime(function.getFunctionStartScheduledTime());
        functioninfo.setFunctionStartTime(function.getFunctionStartTime());
        functioninfo.setFunctionChargerName(getFunctionChargerName(function.getFunctionChargerId()));

        return functioninfo;
    }

    @Override
    public String getFunctionChargerName(Integer userId) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria1 = userExample.createCriteria();
        criteria1.andUserIdEqualTo(userId);
        List<User> users = userMapper.selectByExample(userExample);
        String result =  users.get(0).getUserName();
        return result;
    }

    @Override
    public FunctionPoint getFpInfo(Integer functionPointId) {
        return functionPointMapper.selectByPrimaryKey(functionPointId);
    }

}
